<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加/修改游戏</title>
<%@ include file="/view/common/tags.jsp"%>
</head>
<body>
	<div class="well well_p" >
		<sk:form method="post" cssClass="form-horizontal" action="" id="saveAndUpdateFrom" target="_parent"  enctype="multipart/form-data">
			<div class="form-group">
				<label class="col-xs-3 text-right">装备分类:</label>
				<div class="col-xs-4">
					<sk:select cssClass="form-control select" id="parentId" name="equipParentId" value="${page.wm.ROW_ID}" requiredInit="true" ajaxURL="${userInfoV1}/gameGoodsType/typeSelect?wm[TYPE_FLAG]=11" onchange="TagUtil.fillOptions('parentId');">
						<option value="">请选择</option>
					</sk:select>
					<input type="hidden" name="equipParentName" id="equipParentName" value="">
				</div>
			</div>

			<div class="form-group">
				<label class="col-xs-3 text-right">装备类型:</label>
				<div class="col-xs-4">
					<sk:select cssClass="form-control select" id="equipTypeId" name="equipTypeId" value="${page.wm.EQUIP_TYPE_ID}" ajaxURL="${userInfoV1}/gameGoodsType/smallTypeSelect?wm[OPEN_FLAG]=1" parentCascadedSelect="parentId" parentParamName="parentId" onchange="TagUtil.fillOptions('equipTypeId');" >
						<option value="">请选择</option>
					</sk:select>
					<input type="hidden" name="equipType" id="equipType" value="">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-3 text-right">装备最低等级:</label>
				<div class="col-xs-7">
					<input type="text" class="input" name="equipLowLevel" id="equipLowLevel" value=""  placeholder="请输入置换数量">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-3 text-right">最低插槽数量:</label>
				<div class="col-xs-7">
					<input type="text" class="input" name="equipLowSlotNum" id="equipLowSlotNum" value=""  placeholder="请输入最低插槽数量">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-3 text-right">最高插槽数量:</label>
				<div class="col-xs-7">
					<input type="text" class="input" name="equipHighSlotNum" id="equipHighSlotNum" value=""  placeholder="请输入最高插槽数量">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-3 text-right">排序号:</label>
				<div class="col-xs-7">
					<input type="text" class="input" name="orderByNo" id="orderByNo" value=""  placeholder="请输入排序编号">
				</div>
			</div>

			<input type="hidden" id="rowId" name="rowId" value="<%=request.getParameter("rowId")%>">
           	<input type="hidden" id="token" name="token" value="">
           	<input type="hidden" id="gameIcon" name="gameImgPage" value="${tlzsGame.gameIcon}">
           	<input type="hidden" id="flag"  value="<%=request.getParameter("flag")%>">
           	<input type="hidden" id="isReCommit" value="0">
		</sk:form>	
	</div>
</body>
<%@ include file="/view/common/footer.jsp"%>
<script type="text/javascript">
$(function(){
    $("#token").val(sessionStorage.getItem("token"));
    var rowId = $("#rowId").val();
    if(rowId > 0){
        $.ajax({
            url: "${userInfoV1}/gameEquipSlot/getGameEquipSlotInfo?r="+Math.random(),
            type: "post",
            cache: false,
            data:{"rowId":rowId},
            dataType:"json",
            async:false,
            success: function(data) {
                if (data == null) {
                    return;
                }
                $("#parentId").val(data.equipParentId);
                $("#equipParentName").val(data.equipParentName);
                $("#equipTypeId").val(data.equipTypeId);
                $("#equipType").html(data.equipType);
                $("#equipLowLevel").val(data.equipLowLevel);
                $("#equipLowSlotNum").val(data.equipLowSlotNum);
                $("#equipHighSlotNum").val(data.equipHighSlotNum);
                $("#orderByNo").val(data.orderByNo);


                if(data.openFlag == 1){
                    $("#yse").attr("checked","true");
                    $("#no").removeAttr("checked");
                } else {
                    $("#yse").removeAttr("checked");
                    $("#no").attr("checked","true");
                }
                fillAreaServer(data.equipParentId,data.equipTypeId);
            }
        });
    }
})


function fillAreaServer(parentId,equipTypeId){
    var token = $("#token").val();
    if(parentId > 0){
        $.ajax({
            url: "${userInfoV1}/gameGoodsType/smallTypeSelect?wm[OPEN_FLAG]=1",
            type: "post",
            cache: false,
            data:{"parentId":parentId,"token":token},
            dataType:"json",
            async:false,
            success: function(data) {
                if (data == null) {
                    return;
                }
                $("#equipTypeId").empty();
                $.each(data, function (index, item) {
                    var id = item.value;
                    var text = item.label;
                    // $("#areaId").append("<option value='"+id+"'>"+text+"</option>");
                    var option = "<option value='"+id+"' "
                    if (equipTypeId == id){
                        option += " selected = 'selected'  ";
                    }
                    option += " >"+text+"</option>"
                    $("#equipTypeId").append(option);
                });
            }
        });
    }
}



var err = {'1':'添加','2':'修改'};
var action = {'1':'/save','2':'/update'};
function add(){
    var rowId = $('#rowId').val();
    var i;
    if (!CheckUtil.isNotNull(rowId) || rowId == 0) {
        i = 1;//添加
    } else {
        i = 2;//修改
    }
    var parentId = $.trim($("#parentId").val());
    if (!CheckUtil.isNotNull(parentId)) {
        layer.msg("请选择装备类型!");
        return;
    }

    var equipParentName = $("#parentId").find("option:selected").text();
    $("#equipParentName").val(equipParentName);


    var equipTypeId = $.trim($("#equipTypeId").val());
    if (!CheckUtil.isNotNull(equipTypeId)) {
        layer.msg("请选择装备分类!");
        return;
    }

    var equipType = $("#equipTypeId").find("option:selected").text();
    $("#equipType").val(equipType);


    var orderByNo = $('#orderByNo').val();
    if (!CheckUtil.isNotNull(orderByNo)) {
        layer.msg("排序号不能为空!");
        return;
    }

    //loading层
    var index = layer.load(0, {
        shade: [0.1,'#fff'] //0.1透明度的白色背景
    });
    
    $.ajax({
        url: "${userInfoV1}/gameEquipSlot" + action[i],
        type: "post",
        cache: false,
        //data:parseJson(decodeURIComponent($("#saveAndUpdateFrom").serialize())),
        data: new FormData($("#saveAndUpdateFrom")[0]),
        dataType:"json",
        processData: false,
        contentType: false,
        async:false,
        success: function(data) {
            layer.close(index);
            if(data.code == 0){
                parent.layer.msg("添加成功！");
            } else if(data.code == 1){
                parent.layer.msg("修改成功！");
            } else if(data.code == "-2"){
                parent.window.location.href="${sysManagerV1}/";
            } else {
                parent.layer.msg(data.message);
            }
            if(data.code >= 0){
                parent.findData();
                parent.layer.close(parent.tableIndex);
            }
        }
    });
    
/*    
    $("#saveAndUpdateFrom").attr("action", "${userInfoV1}/baseGame" + action[i]);
    if ($("#isReCommit").val() == 0) {
        $("#isReCommit").val(1);
        //loading层
        var index = layer.load(0, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });
        //$("#saveAndUpdateFrom").submit();
    } */
}

function checkGameName() {
    //渠道游戏ID
    var gameName = $.trim($("#gameName").val());
    $("#gameName").val(gameName);//渠道游戏ID去空格
    var flag = $("#flag").val();
    var rowId = $("#rowId").val();;
    var aa = false;
    if (CheckUtil.isNotNull(gameName)) {
        $.ajax({
            type: "post",
            cache: false,
            url: "${userInfoV1}/baseGame/checkGameIsExist",
            data:{gameName:gameName, gameId:rowId},
            dataType:"json",
            async:false,
            success: function(data) {
                aa = data;
            }
        });
    }
    return aa;
}
</script>
</html>